import numpy as np 
import random

np.random.seed(0)

#矩阵（5*5）  卷积核（3*3）
mat = np.array([[10,10,32,41,93],[13,13,29,52,106],[20,22,43,32,38],[29,89,145,23,110],[23,32,44,26,87]])
[chang,kuan] = mat.shape

#pingjun = 1/9*np.ones((3,3))
#zhongzhi = np.ones((3,3))
renyi = np.array([[1,0,1],[1,1,1],[0,1,0]])
ans = []
for j in range(1,kuan-1):
    for i in range (1,chang-1):
        print(mat[j-1:j+2,i-1:i+2].shape)
        # after_conv = np.sum(pingjun*mat[j-1:j+2,i-1:i+2])
        # after_conv = np.median(mat[j-1:j+2,i-1:i+2])
        after_conv = np.sum(renyi*mat[j-1:j+2,i-1:i+2])
        ans.append(after_conv)

ans =np.array(ans).reshape(3,3)
print(ans)